package com.xucia.jsponic.security;

import java.security.Principal;
import java.security.acl.Acl;
import java.security.acl.AclEntry;
import java.security.acl.LastOwnerException;
import java.security.acl.NotOwnerException;
import java.security.acl.Permission;
import java.util.Enumeration;

import com.xucia.jsponic.data.ObjectId;

public class InheritingAcl implements Acl {
	ObjectId inheritingFrom;
	public InheritingAcl(ObjectId objectToInheritFrom) {
		inheritingFrom = objectToInheritFrom;
	}
	public Acl getInheritedAcl() {
		return inheritingFrom.getTarget().getAcl();
	}
	public boolean addEntry(Principal caller, AclEntry entry) throws NotOwnerException {
		return getInheritedAcl().addEntry(caller, entry);
	}
	public boolean addOwner(Principal caller, Principal owner) throws NotOwnerException {
		return getInheritedAcl().addOwner(caller, owner);
	}
	public boolean checkPermission(Principal principal, Permission permission) {
		return getInheritedAcl().checkPermission(principal, permission);
	}
	public boolean deleteOwner(Principal caller, Principal owner) throws NotOwnerException, LastOwnerException {
		return getInheritedAcl().deleteOwner(caller, owner);
	}
	public Enumeration<AclEntry> entries() {
		return getInheritedAcl().entries();
	}
	public String getName() {
		return getInheritedAcl().getName();
	}
	public Enumeration<Permission> getPermissions(Principal user) {
		return getInheritedAcl().getPermissions(user);
	}
	public boolean isOwner(Principal owner) {
		return getInheritedAcl().isOwner(owner);
	}
	public boolean removeEntry(Principal caller, AclEntry entry) throws NotOwnerException {
		return getInheritedAcl().removeEntry(caller, entry);
	}
	public void setName(Principal caller, String name) throws NotOwnerException {
		getInheritedAcl().setName(caller, name);
	}
	public String toString() {
		return getInheritedAcl().toString();
	}
}
